<!--轮播图上的 导航-->
<template>
  <div class="nav-z">
    <div class="nav-left">
      <ul>
        <!-- <li
          v-for="(item, index) in bannernav"
          :key="item.id"
          class="ul-nav"
          :class="{active: navActive[index]}"
          @mousemove.stop="enter(index)"
          @mouseleave="out(index)"
          @click="jumpList(item)"
        > -->
        <li
          v-for="(item, index) in bannernav"
          :key="item.id"
          class="ul-nav"
          :class="{active: navActive[index]}"
          @mousemove.stop="enter(index)"
          @mouseleave="out(index)"
          @click="jumpList(item)"
        >
          <ol>
            <img :src="item.icon">
            <span>{{ item.name }}</span>
          </ol>

          <div v-show="show">
            <div class="nav-content" v-show="item.is_show" @mouseover.stop="enter(index)">
              <banner-nav-content :children="item.children" :title="item.name"></banner-nav-content>
            </div>
          </div>
        </li>
      </ul>
    </div>

    <div class="right-content">
      <div class="headPortrait">
        <div>
          <span v-show="!LoginDisplay" class="headPortraittext iconfont">&#xe65f;</span>
          <!-- <img v-show="!LoginDisplay" :src="headPortrait"> -->
          <div v-show="LoginDisplay" class="headPortraitHover">
            <img :src="this.$store.state.HeadPortrait">
          </div>

          <p>HI{{this.$store.state.UserName}}您好</p>
          <ul v-show="!LoginDisplay">
            <el-button type="primary" @click="jumLogin" size="mini">登 录</el-button>
            <el-button type="warning" @click="jumpRegister" size="mini">注 册</el-button>
          </ul>
        </div>

        <div class="minbanner">
          <div class="block">
            <el-carousel height="172px">
              <el-carousel-item>
                <ol>
                  <li v-for="(item,index) in minbanner" :key="index" @click="jumpwantBuy(item.id)">
                    <span>
                      求购
                      <i class="iconfont">&#xe704;</i>
                    </span>
                    <i>{{ item.goods_name }} - {{item.brand_name}}</i>
                  </li>
                </ol>
              </el-carousel-item>
            </el-carousel>
          </div>
        </div>
        <!-- 需求  -->
        <div class="demand">
          <ol>
            <li v-for="item in demand" :key="item.id" @click="jumpPages(item.id)">
              <p class="iconfont">{{ item.iconName }}</p>
              <i>{{item.text}}</i>
            </li>
          </ol>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import image from "@/assets/images/headPortrait.png"
import bannerNavContent from "./Banner_nav_content" //子菜单的详情
import bannerIcon1 from "@/assets/icon/bannerIcon1.png"
import bannerIcon2 from "@/assets/icon/bannerIcon2.png"
import bannerIcon3 from "@/assets/icon/bannerIcon3.png"
import bannerIcon4 from "@/assets/icon/bannerIcon4.png"
import bannerIcon5 from "@/assets/icon/bannerIcon5.png"
export default {
  name: "bannerNav",
  data() {
    return {
      bannerIcon:[
        {bannericon:bannerIcon1},
        {bannericon:bannerIcon2},
        {bannericon:bannerIcon3},
        {bannericon:bannerIcon4},
        {bannericon:bannerIcon5},
      ],
      navActive: [],   // 轮播图的导航 active的 保留
      LoginDisplay: false,   // 登陆后的显示的状态
      show: 0,
      headPortrait: image, // 头像
      hello: "HI 您好 !", // 头像下方提示文字
      minbanner: [], // minbanner 内容
      demand: [
        {
          iconName: `\ue62b`,
          text: "发布求购",
          id: 0
        },
        {
          iconName: "\ue622",
          text: "快速下单",
          id: 1
        },
        {
          iconName: "\ue63e",
          text: "需求查看",
          id: 2
        }
      ]
    }
  },

  methods: {
    // 主页导航轮播图的点击事件
    // !item.children 条件 确保没有子选项的情况下才可以进行跳转 否则需要选择子选项
    jumpList(item) {
      if (!item.children) {
        this.$store.commit('ListTreeId', item.id)
        this.$router.push({
          name: "productList",
          params: {
            id: item.id,
            item
          }
        })
      }
    },

    // 获取个人资料
    async receiveInfor() {
      let user_id = this.$store.state.UserInfor.user_id
      let status = "user"
      try {
        let infor = await this.$http({
          method: "post",
          url: "/api/index/web/doSelfInfos",
          data: {
            user_id,
            status
          }
        })
        const myInfor = infor.data
        if (myInfor.State.Code == 200) {
          // console.log(myInfor.data)
          this.$store.commit("HeadPortrait", myInfor.data.avatar)
          this.$store.commit("UserName", myInfor.data.name)
          // 下面的两条未进行处理
          //     department_id: null,
          //     sex: null,
        }
      } catch (error) {
        console.log("获取个人资料接口出现了问题...")
      }
    },
    // 登陆后的显示的状态
    loginDisplay() {
      const jwt = localStorage.getItem("token")
      // console.log(jwt)
      if (jwt) {
        this.LoginDisplay = true
      } else {
        this.LoginDisplay = false
      }
    },
    // 获取首页的求购信息
    async purchaseInfo() {
      try {
        let info = await this.$http("/api/index/index/getIndexBuying")
        const _data = info.data.data
        if (info.data.State.Code == 200) {
          this.minbanner = _data
        }
      } catch (error) {
        console.log(error)
      }
    },

    // 三个带图标的按钮 点击详情
    jumpPages(ev) {
      switch (ev) {
        case 0:
          this.$router.push({
            name: "purchaseCenter",
            params: {
              sonshow: 0
            }
          })
          break
        case 1:
          this.$router.push({
            name: "QuickOrder"
          })
          break
        case 2:
          this.$router.push({
            name: "MyWantBuy",
            params: {
              id: 7
            }
          })
          this.$store.commit('leftIndex',7)   // 点击的id存在 leftIndex
          break
      }
    },

    // 求购 内容 点击 跳转
    jumpwantBuy(ev) {
      this.$router.push({
        name: "purchaseCenter",
        params: {
          sonshow: true // 点击判断显示另一个页面的
        }
      })
    },

    // 跳转登录页面
    jumLogin() {
      if (localStorage.getItem("token")) {
        this.$notify({
          title: "您已经登录 请勿重复登录...",
          // message: '请重新登录您的账号...',
          type: "success"
        })
      } else {
        this.$router.push("/login") //跳转到登陆页面
      }
    },

    // 跳转注册页面
    jumpRegister() {
      this.$router.push("/register")
    },

    // 鼠标进入时候出发的函数
    enter(index) {
      setTimeout(()=>{
        this.show = 1
        this.bannernav[index].is_show = 1
        this.navActive[index] = 1 //  用来控制nav
      })
      // this.show = 1
      // this.bannernav[index].is_show = 1
      // this.navActive[index] = 1 //  用来控制navActive在进入子菜单时 仍然保持的active
    },

    // 鼠标离开时候触发的函数
    out(index) {
      this.show = 0
      this.bannernav[index].is_show = 0
      this.navActive[index] = 0 //  用来控制navActive在进入子菜单时 仍然保持的active 
    },


  },

  components: {
    bannerNavContent
  },

  computed: {
    bannernav() {
      let bannerArr = [...new Set(this.$store.state.bannernav)]
      let flagArr = bannerArr.map((item, index)=>{
        item.icon = this.bannerIcon[index].bannericon
        return item
      })

      return flagArr
    }
  },

  mounted() {
    this.purchaseInfo() // 求购信息的接口介入
    this.receiveInfor()
  },
  // 关于state的 状态改变 放在这个钩子中 如果放在上面的钩子不生效 检测不到数据的变化
  updated() {
    this.loginDisplay()
  }
}
</script>

<style lang="scss" scoped>
.nav-z {
  width: 1200px;
  height: 420px;
  position: absolute;
  top: 0px;
  left: calc((100% - 1200px) / 2);
  z-index: 1;
  margin: auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  .nav-left {
    width: 212px;
    min-height: 420px;
    background-color: rgba($color: #000000, $alpha: 1);
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    // /*滚动条样式*/
    // &::-webkit-scrollbar {/*滚动条整体样式*/
    //     width: 4px;     /*高宽分别对应横竖滚动条的尺寸*/
    //     height: 4px;
    // }
    // &::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
    //     border-radius: 5px;
    //     // -webkit-box-shadow: inset 0 0 5px rgba(245, 101, 6, 0.5);
    //     background: rgba(121, 118, 118, 0.973);
    // }
    // &::-webkit-scrollbar-track {/*滚动条里面轨道*/
    //     // -webkit-box-shadow: inset 0 0 5px rgba(245, 101, 6, 0.5);
    //     border-radius: 0;
    //     background: rgba(193, 236, 233, 0.918);
    // }
    ul {
      box-sizing: border-box;
      color: #fff;
      width: 212px;
      height: 420px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .ul-nav {
        box-sizing: border-box;
        position: relative;
        border-bottom: #181818 1px solid;
        ol{
          width: 100%;
          font-size: 14px;
          cursor: pointer;
          height: 83px;
          line-height: 83px;
          display: flex;
          flex-direction: row;
          align-items: center;
          img{
            width: 18px;
            padding-left: 37px;
          }
          span{
            padding-left: 8px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }
        .nav-content {
          width: 988px;
          height: 420px;
          background: #ffffff;
          position: fixed;
          top: 0px;
          margin-left: 212px;
          color: #000;
          z-index: 100;
        }
      }
      .active {
        color: #fff;
        background: #181818;
      }
    }
  }

  .right-content {
    width: 212px;
    height: 390px;
    background-color: rgba($color: #000000, $alpha: 0.8);
    color: #ffffff;
    cursor: pointer;
    .headPortrait {
      width: 100%;
      height: 36px;
      margin-top: 20px;
      .headPortraittext {
        display: inline-block;
        text-align: center;
        width: 100%;
        font-size: 40px;
        font-weight: 300;
      }
      img {
        margin: auto;
        width: 60px;
        height: 60px;
        display: block;
        margin: auto;
        border-radius: 50%;
        overflow: hidden;
      }
      .headPortraitHover {
        position: relative;
        transition: all 0.7s ease-in;
      }
      p {
        margin: auto;
        width: 90%;
        line-height: 40px;
        text-align: center;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-family: "微软雅黑";
      }
      ul {
        width: 76%;
        height: 26px;
        margin: auto;
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        li {
          width: 78px;
          height: 26px;
          line-height: 26px;
          text-align: center;
          border-radius: 5px;
          background: #006aee;
          letter-spacing: 2px;
          &:hover {
            color: #006aee;
            background: #fff;
          }
        }
      }
      .minbanner {
        width: 100%;
        height: 172px;
        .block {
          ol {
            padding-top: 20px;
            padding-left: 25px;
            li {
              line-height: 25px;
              font-size: 12px;
              display: flex;
              flex-direction: row;
              align-items: center;

              &:hover {
                span {
                  i {
                    transition: all 0.3s ease-in;
                    width: 20px;
                    font-size: 14px;
                    font-weight: bold;
                    margin-right: 3px;
                    color: #f40;
                  }
                }
              }
              span {
                display: flex;
                flex-direction: row;
                align-items: center;
                i {
                  width: 20px;
                  font-size: 13px;
                  margin: 0px 3px;
                }
              }
              i {
                width: 112px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              }
            }
          }
        }
      }
      .demand {
        width: 100%;
        ol {
          width: 172px;
          margin: auto;
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          font-size: 12px;
          color: #ffe400;
          letter-spacing: 0.8px;
          li {
            &:hover {
              p {
                transition: all 0.3s ease-in-out;
                font-size: 34px;
              }
            }
            p {
              font-size: 30px;
            }
          }
        }
      }
    }
  }
}
@media screen and (max-width: 1196px) {
  .nav-z {
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 0;
  }
}
</style>
<style>
.minbanner .block .el-carousel__indicator {
  display: none !important;
}
.minbanner .block button {
  display: none !important;
}
</style>

